function obj = LockXe129(obj)
    L = log4m.getLogger;
    
    gain129 = obj.SystemInfo.Xe129FID.T2*360.0*obj.SystemInfo.Xe129FID.f129/obj.SystemInfo.MainField.bz0;
    order129 = obj.Xe129.getSetting('order');
    bw129 = obj.Xe129.getSetting('bandwidth');

    %%
    s=tf('s');
    fltr129 = 1/(1+ziBW2TC(bw129, order129)*s)^order129;
    nmr = gain129/(1+obj.SystemInfo.Xe129FID.T2*s);
    [gm129, ~, wgm129, ~] = margin(fltr129*nmr);
    lock129 = EquipmentControl.FeedBackOptimization.ZieglerNichols.getPID_ZN(gm129, 2*pi/wgm129);
    
    %%
    obj.ziSlave.setPIDMode('2', 0);
    obj.ziSlave.setPIDInput('2', 3); % DemodPhase
    obj.ziSlave.setPIDInputChannel('2', 2); % ziDemod '2'
    obj.ziSlave.setPIDSetpoint('2', -90.0);
    obj.ziSlave.disablePIDPhaseUnwarp('2');
    obj.ziSlave.setPIDOutput('2', 5);
    obj.ziSlave.setPIDOutputChannel('2', 2);
    obj.ziSlave.setPIDCenter('2', obj.SystemInfo.MainField.bz0);
    obj.ziSlave.setPIDLimLower('2', -2e-3);
    obj.ziSlave.setPIDLimUpper('2', 2e-3);
    obj.ziSlave.setPValue('2', lock129.pVal);
    obj.ziSlave.setIValue('2', lock129.iVal);
    obj.ziSlave.setDValue('2', lock129.dVal);
    obj.ziSlave.setDLimValue('2', 1e3);
    obj.ziSlave.setRateValue('2', 2e6);
    obj.ziSlave.lock('2');
    L.info('NMRGyroscope::LockXe129', sprintf('Xe129 is locked: P=[%5.3e], I=[%5.3e], D=[%5.3e]', lock129.pVal, lock129.iVal, lock129.dVal));
end

